package emulator.hardware.nmos6502.commands;

import emulator.EmulatorException;
import emulator.hardware.nmos6502.Command;
import emulator.hardware.nmos6502.CommandSet;
import emulator.hardware.nmos6502.Cpu6502;
import emulator.hardware.nmos6502.Operand;
import emulator.hardware.nmos6502.operands.ImmediateAddress;
import emulator.hardware.nmos6502.stack.StackData;

/** JSR (Jump to SubRoutine) */
public class JSR implements Command {

	@Override
	public void execute(Cpu6502 cpu, Operand operand) throws EmulatorException {
		cpu.pushAddress(cpu.getPC()-1, StackData.SOURCE_JUMP);
		cpu.setPC((int) operand.getWord().getNumber());
		
		cpu.notifyCall();
	}

	@Override
	public String getName() {
		return "JSR";
	}

	@Override
	public void register(CommandSet cset) {
		cset.defineCommand(0x20, this, new ImmediateAddress(), 5);
	}

}
